<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="报工日期" prop="rfworkDate">
        <el-date-picker clearable
          v-model="queryParams.rfworkDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择报工日期">
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="rfworkList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="报工日期" align="center" prop="rfworkDate" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.rfworkDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="报工人" align="center" prop="rfworkNick" />
      <el-table-column label="直属领导" align="center" prop="leaderNick" />
      <el-table-column label="领导审核通过" align="center" prop="leaderPass" width="150">
        <template slot-scope="scope">
          <span v-if="scope.row.leaderPass == '0'">通过</span>
          <span v-else-if="scope.row.leaderPass == '1'">未通过</span>
        </template>
      </el-table-column>
      <el-table-column label="复核人" align="center" prop="recheckNick" />
      <el-table-column label="复核通过" align="center" prop="recheckPass" >
        <template slot-scope="scope">
          <span v-if="scope.row.recheckPass == '0'">通过</span>
          <span v-else-if="scope.row.recheckPass == '1'">未通过</span>
        </template>
      </el-table-column>

      <el-table-column label="领导审核时间" align="center" prop="leaderDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.leaderDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="复核时间" align="center" prop="recheckDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.recheckDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="类别" align="center" prop="rfwordType" >
        <template slot-scope="scope">
          <span v-if="scope.row.rfwordType == '0'">计件报工</span>
          <span v-else-if="scope.row.rfwordType == '1'">零工报工</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleRworkList(scope.row)"
          >报工项列表</el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>

</template>

<script>
import { listRfwork, getRfwork, delRfwork, addRfwork, updateRfwork } from "@/api/sl/rfwork";

export default {
  name: "Rfwork",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报工单表格数据
      rfworkList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        rfworkDate: null,
        rfworkUser: null,
        rfworkNick: null,
        leaderUser: null,
        leaderNick: null,
        isNew: null,
        leaderPass: null,
        recheckUser: null,
        recheckNick: null,
        recheckPass: null,
        leaderDate: null,
        recheckDate: null,
        rfworkShifts: null,
        rfworkYear: null,
        rfworkMonth: null,
        rfworkDay: null,
        rfwordType: null,
        isStatistics: null,
        moduleId: null,
        workshopId: null,
        gprocessId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询报工单列表 */
    getList() {
      this.loading = true;
      listRfwork(this.queryParams).then(response => {
        this.rfworkList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        rfworkId: null,
        rfworkDate: null,
        rfworkUser: null,
        rfworkNick: null,
        leaderUser: null,
        leaderNick: null,
        isNew: null,
        leaderPass: null,
        recheckUser: null,
        recheckNick: null,
        recheckPass: null,
        leaderDate: null,
        recheckDate: null,
        rfworkShifts: null,
        rfworkYear: null,
        rfworkMonth: null,
        rfworkDay: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        rfwordType: null,
        isStatistics: null,
        moduleId: null,
        workshopId: null,
        gprocessId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.rfworkId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加报工单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const rfworkId = row.rfworkId || this.ids
      getRfwork(rfworkId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改报工单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.rfworkId != null) {
            updateRfwork(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRfwork(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const rfworkIds = row.rfworkId || this.ids;
      this.$modal.confirm('是否确认删除报工单编号为"' + rfworkIds + '"的数据项？').then(function() {
        return delRfwork(rfworkIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('sl/rfwork/export', {
        ...this.queryParams
      }, `rfwork_${new Date().getTime()}.xlsx`)
    },
    handleRworkList(row){
      const bgType = row.rfwordType;
      const rfworkId = row.rfworkId;
      if(bgType==="0"){
        this.$router.push({ path: "/hrwork/hwork", query: {"rfworkId": rfworkId} });
      }else if(bgType==="1"){
        this.$router.push({ path: "/hrwork/hoddjob", query: {"rfworkId": rfworkId} });
        // this.$router.push("/rfwork/hoddjob/list/" + rfworkId);
      }
    },


  }
};
</script>
